// 导出页面为PDF格式
import html2Canvas from 'html2canvas'
import JsPDF from 'jspdf'
export default {
    install(Vue, options) {
        Vue.prototype.getPdf = function (dom) {
            var title = this.htmlTitle
            var target = document.querySelector(dom ? dom : '#pdfDom')
            html2Canvas(target, {
                allowTaint: true,
                scale: 1.1,
            }).then(function (canvas) {
                const contentWidth = canvas.style.width.split('px')
                const contentHeight = canvas.style.height.split('px')
                const pdfWidth = Number(contentWidth[0])
                const pdfHeight = Number(contentHeight[0])
                const pageData = canvas.toDataURL('image/jpeg', 1.0)
                const PDF = new JsPDF('', 'pt', [pdfWidth, pdfHeight,])
                PDF.addImage(pageData, 'jpeg', 0, 0, pdfWidth, pdfHeight)
                PDF.save(title + '.pdf')
            })
        }
    }
}
